package aqr;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Fibbonacci {

	public static void main(String[] args) {
		int length = 0;
		System.out.print("Enter the length: ");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			length = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			System.out.println("Invalid Entry");
		}
		
		System.out.println("Using Iteration, the first "+length+" numbers in the Fibbonacchi sequence are:");
		for(int i = 1; i <= length; i++) {
			System.out.print(fibbonacci1(i)+" ");
		}
		
		System.out.println("\nUsing Recursion, the first "+length+" numbers in the Fibbonacchi sequence are:");
		for(int i = 1; i <= length; i++) {
			System.out.print(fibbonacci2(i)+" ");
		}
	}
	
	public static int fibbonacci1(int num){
		if (num == 1 || num ==2 ) 
			return 1;
		
		int fib1 = 1, fib2 = 1, cur = 1; 
		for (int i = 2; i < num; i++) {
			cur = fib1 + fib2;
			fib1 = fib2;
			fib2 = cur;
		}
		return cur;
	}
	
	public static int fibbonacci2(int n) {
		if (n == 1 || n == 2)
			return 1;
		else return fibbonacci2(n-2)+fibbonacci2(n-1);
	}
}
